// pages/member-friendList/member-friendList.js
import api from '../../utils/api.js'
let app = getApp();
import {
    HTTP
} from '../../utils/http.js'
let http = new HTTP()
import { config } from '../../utils/config'
Page({
    data: {
        // 此页面 页面内容距最顶部的距离
        height: app.globalData.height * 2 + 20,
        imgUrl: config.imgUrl,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let user_id = wx.getStorageSync('user_id');
        this.getCronyList(user_id);
    },

    //拿到好友列表
    getCronyList(user_id) {
        http.request({
            url: api.getCronyList,
            data: {
                id: user_id,
            },
            success: (res) => {
                console.log('拿到好友列表', res);
                if (res.code == 200) {
                    let arrList = this.handleFriendData(res.data);
                    console.log(arrList)
                    this.setData({
                        friendList: res.data,
                        arrList
                    })
                }
            }
        });
    },
    //处理好友数据，金币总和，剔除排名，合并成数组
    handleFriendData(data) {
        let arr = []
        for (let key in data) {
            console.log(key);

            if (data[key] instanceof Object) {
                arr.push(data[key])
            }
        }
        return arr;
    },


    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    }
})